﻿using Newtonsoft.Json;
using System.IO;
using System.Windows.Forms;

namespace QWManage.MySqlSync
{
    public class MysqlSyncCfgInfo
    {
        public string MysqlServer { set; get; }
        public string MysqlUser { set; get; }
        public string MysqlDataBase { set; get; }
        public string MysqlPort { set; get; }
        public string MysqlPassword { set; get; }
        public string Owner { set; get; }

        public string MssqlDataSource { set; get; }
        public string MssqlInitialCatalog { set; get; }
        public string MssqlUserID { set; get; }
        public string MssqlPassword { set; get; }

    }

    public class MysqlSyncCfgMgr
    {
        private static string NAME = "MysqlSyncCfg.dll";
        public static MysqlSyncCfgInfo Get()
        {
            MysqlSyncCfgInfo obj = null;
            try
            {
                string fn = Path.Combine(Application.StartupPath, NAME);
                if (File.Exists(fn))
                {
                    string json = File.ReadAllText(fn);
                    obj = JsonConvert.DeserializeObject<MysqlSyncCfgInfo>(json);
                    return obj;
                }
            }
            catch { }
            if (obj == null) { obj = new MysqlSyncCfgInfo(); }
            return obj;
        }

        public static void Set(MysqlSyncCfgInfo info)
        {
            try
            {
                string fn = Path.Combine(Application.StartupPath, NAME);
                {
                    string json = JsonConvert.SerializeObject(info);
                    File.WriteAllText(fn, json);
                }
            }
            catch { }
        }
    }
}
